const { readFileSync, writeFileSync } = require('fs')
const path = require('path')

function ctrldb(dbname, func) {
    const dbPath = path.join(__dirname, `../db/${dbname}.json`)
    const data = JSON.parse(readFileSync(dbPath))
    const newData = func(data)
    if(!newData) return
    writeFileSync(dbPath, JSON.stringify(newData))
}

module.exports = ctrldb